import json

from devicetest.api import Asserts

from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step
from devicetest.log.logger import print_info
from aw.common import common_setup, common_teardown
from aw.pom import Memorandum


class PreTest_RK3568_Tooling_Memorandum_0800(TestCase, Memorandum):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 1、进入桌面，点击备忘录应用，点击搜索笔记框输入要搜索的内容
    # 预期结果：
    # 1、点击搜素框可唤醒键盘，显示无遮挡，搜索显示结果与搜索框输入的关键词一致

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)

    def process(self):
        Step('步骤1：1、进入桌面，点击备忘录应用，点击搜索笔记框输入要搜索的内容')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.touchByType(self.Phone1, 'TextInput')
        CommonOH.inputTextByType(self.Phone1, type='TextInput', content='UX')
        Step('预期结果1：点击搜素框可唤醒键盘，显示无遮挡，搜索显示结果与搜索框输入的关键词一致')
        # 键盘
        CommonOH.checkIfTextExist(self.Phone1, 'space')
        print_info('键盘被唤醒')
        CommonOH.checkIfTextExist(self.Phone1, 'UX会议纪要')
        print_info('搜索显示结果与搜索框输入的关键词一致')
        search_bounds = json.loads(CommonOH.getWidgetProperties(self.Phone1, 'type/TextInput'))['bounds']
        result_bounds = json.loads(CommonOH.getWidgetProperties(self.Phone1, 'UX会议纪要'))['bounds']
        keyboard_bounds = json.loads(CommonOH.getWidgetProperties(self.Phone1, '1'))['bounds']
        Asserts.assert_greater(result_bounds['topY'], search_bounds['bottomY'])
        Asserts.assert_greater(keyboard_bounds['topY'], result_bounds['bottomY'])
        print_info('显示无遮挡')

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
